from abc import ABC, abstractmethod
from dataclasses import dataclass
from enum import Enum
import json
from typing import Optional

class PDFTaskType(Enum):
    PARSE = 0
    DELETE = 1

class PDFTask(ABC):
    def __init__(self, task_type: PDFTaskType) -> None:
        super().__init__()
        self._task_type = task_type
        
    @abstractmethod
    def handle(self):
        raise NotImplementedError
    
@dataclass
class KqPaperMeta:
    id: str
    update_at: int
    create_at: int
    
    file_name: str
    file_size: int
    content_type: str
    user_id: int
    
    status: str
    minio_bucket: str
    minio_object: str
    etag: str
    
    parse_status: str

    @classmethod
    def from_json(cls, json_str: str) -> Optional['KqPaperMeta']:
        data = json.loads(json_str)
        return cls(
            id=data.get('id'),
            update_at=data.get('updateAt'),
            create_at=data.get('createAt'),
            file_name=data.get('file_name'),
            file_size=data.get('file_size'),
            content_type=data.get('content_type'),
            user_id=data.get('user_id'),
            status=data.get('status'),
            minio_bucket=data.get('minio_bucket'),
            minio_object=data.get('minio_object'),
            etag=data.get('etag'),
            parse_status=data.get('vector_status')
        )
